package com.doublefish.doublefishrobot.utils;

import android.view.View;


//按钮防抖
//点击事件的监听
public abstract class DebounceOnClickListener implements View.OnClickListener {

    private float interval = 0.5f;
//    private float interval = 5f;

    private long timeMillis = 0;

    public DebounceOnClickListener() {

    }

    public DebounceOnClickListener(float interval) {
        if (interval <= 0) {
            interval = 0.5f;
        }
        this.interval = interval;
    }

    @Override
    public void onClick(View view) {

        long currentTimeMillis = System.currentTimeMillis();
        if (currentTimeMillis >= timeMillis + (long)(interval * 1000)) {
            timeMillis = currentTimeMillis;
            onClickView(view);
        }
    }

    protected abstract void onClickView(View view);
}
